package com.hxx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hxx.entity.PassengerEntity;
import com.hxx.service.PassengerService;
import com.hxx.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/passenger")
public class PassengerController {
    @Autowired
    private PassengerService passengerService;

    /**
     * 分页查询
     */
    @GetMapping("page")
    public R listPage(Page<PassengerEntity> page, PassengerEntity entity) {
        passengerService.findPage(page, entity);
        return R.ok().data("list", page.getRecords())
                .data("total", page.getTotal());
    }

    /**
     * 添加
     */
    @PostMapping("add")
    public R add(@RequestBody PassengerEntity entity) {
        passengerService.save(entity);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("update")
    public R update(@RequestBody PassengerEntity entity) {
        passengerService.updateById(entity);
        return R.ok();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable Long id) {
        passengerService.removeById(id);
        return R.ok();
    }
}























